home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / mergec.com / MERGEC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-04  |  4.7 KB  |  142 lines

  1. /*******************************************************************
  2. *                                                                  *
  3. *   MERGEC                                                         *
  4. *       This program reads in a Turbo C file and the Assembler        *
  5. *       file that tcc produced (with the -S switch) and combines   *
  6. *    them into a single file.  This function is useful when     *
  7. *    trying to debug in Assembler code with a hardware debugger *
  8. *    or if you are just interested in how well Borland        *
  9. *    generate Assembler code.                   *
  10. *                                                                  *
  11. *   COMMAND FORMAT:                                                *
  12. *     MERGEC asmsrc csrc mergefile                   *
  13. *             or                           *
  14. *    MERGEC filename                           *
  15. *         and the program will assume the following:           *
  16. *                assembler source --> filename.asm       *
  17. *                C source  ---------> filename.c           *
  18. *                "merged source" ---> filename.mer       *
  19. *                                                                  *
  20. *                                   *
  21. *   This program was adapted from source by Dan Mick in the        *
  22. *   July 1989 issue of "Microsoft Systems Journal."   The          *
  23. *   original program supported the Microsoft compiler and MASM.    *
  24. *   This program only supports Turbo C.                            *
  25. *                                   *
  26. *   Send comments or suggestions to:                   *
  27. *                                   *
  28. *      Rick Kamp  (GENIE: R.KAMP)                   *
  29. *                 (COMPUSERVE: 72311,2346)                         *
  30. *                                   *
  31. *      COPYRIGHT (c) Rick Kamp, 1989                   *
  32. *      ALL RIGHTS RESERVED                       *
  33. *                                   *
  34. *   CHANGE HISTORY:                                                *
  35. *                                                                  *
  36. *                               Version 1.00   04 Jul 1989         *
  37. *******************************************************************/
  38. /* mergec - merge source and assembly files */
  39.  
  40. #include <stdio.h>
  41. #include <string.h>
  42.  
  43. main(argc,argv)
  44. int argc;
  45. char *argv[];
  46. {
  47.     FILE *csrc, *asmsrc, *mergefile;
  48.     char buffer[128];
  49.     char rest_of_line[128];
  50.     long sline, line, totslines;
  51.     char filename1[80],filename2[80],filename3[80];
  52.  
  53.     if (argc >4 || argc ==1 || argc==3) {
  54.         printf("usage: mergec asmsrc csrc mergefile\n");
  55.         printf("                or\n");
  56.         printf("usage: mergec filename\n");
  57.         printf("    and the program will assume the following:\n");
  58.         printf("       assembler source --> filename.asm\n");
  59.         printf("       C source  ---------> filename.c\n");
  60.         printf("       \"merged source\" ---> filename.mer\n");
  61.         exit(1);
  62.     }
  63.  
  64.     sline = 0;
  65.     if (argc==2) {
  66.         strcpy(filename1, argv[1]);
  67.             strcat(filename1, ".asm\0");
  68.         strcpy(filename2, argv[1]);
  69.             strcat(filename2, ".c\0");
  70.         strcpy(filename3, argv[1]);
  71.             strcat(filename3, ".mer\0");
  72.     }
  73.     else
  74.     {
  75.         strcpy(filename1, argv[1]);
  76.         strcpy(filename2, argv[2]);
  77.         strcpy(filename3, argv[3]);
  78.     }
  79.     if ((asmsrc = fopen(filename1,"r"))==0) {
  80.         printf("Cannot open <%s>\n",filename1);
  81.         exit();
  82.     }
  83.     if ((csrc = fopen(filename2,"r"))== 0) {
  84.         printf("Cannot open <%s>\n",filename2);
  85.         exit();
  86.     }
  87.     if ((mergefile = fopen(filename3,"w"))==0) {
  88.         printf("Cannot open <%s>\n",filename3);
  89.         exit();
  90.     }
  91.  
  92.     setvbuf(csrc,NULL,_IOFBF,8192);
  93.     setvbuf(asmsrc,NULL,_IOFBF,8192);
  94.     setvbuf(mergefile,NULL,_IOFBF,8192);
  95.  
  96.     totslines = 0;
  97.     while (fgets(buffer,128,csrc) != NULL)
  98.         totslines++;
  99.     fseek(csrc,0L,SEEK_SET);
  100.  
  101.     while ((fgets(buffer,128,asmsrc)) !=NULL) {
  102.  
  103.         if (strncmp(buffer,";\t?debug\tL",10) == 0) {
  104.            sscanf(buffer,";\t?debug\tL %ld",&line);
  105.            if (line <= totslines) {
  106. /*  un-comment the following line to set an HP printer to bold text     */
  107. /*  You may also set this string to another escape sequence to support  *
  108.  *  your own printer.                            */
  109. /*             fprintf(mergefile,"\x1B(s3B");                */
  110.              while (sline < line) {
  111.             fgets(buffer+1,128,csrc);
  112.             fputs(buffer,mergefile);
  113.             ++sline;
  114.              }
  115. /*  un-comment the following line to set an HP printer to normal text */
  116. /*             fprintf(mergefile,"\x1B(s0B\x0D");               */
  117.            }
  118.         }
  119.         else
  120.            if (strncmp(buffer,"\t?debug\tC",9) ==0) {
  121.            continue;
  122.         }
  123.         else
  124.            if (strncmp(buffer,"\t?debug\tS",9) ==0) {
  125.            strcpy(rest_of_line,buffer+10);
  126.            fputs(";*****************************************************************\n"
  127.               ,mergefile);
  128.            fprintf(mergefile,"; source file : %s",rest_of_line);
  129.            fputs(";*****************************************************************\n"
  130.               ,mergefile);
  131.            continue;
  132.         }
  133.         else
  134.         {
  135.         fputs(buffer,mergefile);
  136.         }
  137.     }
  138.     fclose(asmsrc);
  139.     fclose(csrc);
  140.     fclose(mergefile);
  141. }
  142.